package wuxianshua.profile;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Datetime:    2021/1/24   23:18
 * Author:   jianglei
 */
public class Main {
    static Map <Long,String>fileNameMap = new HashMap();
    public static void main(String[]args) throws IOException {


    }

    static public void  updateVoc(){

    }

    public static  void copyFile(String path) throws IOException {
        File file = new File(path);
        if(file.getName().contains("视频")){
            System.out.println("跳过文件:"+file.getName());
            return;
        }
        if(file.isFile()){
            String fileName = file.getName();
            if(fileName.contains("xml")){//xml文件
                FileUtils.copyFile(file,new File("D:\\资料\\CV\\video\\dataset\\xml",fileName));
                System.out.println("正在复制xml:"+fileName);
            }else if(fileName.contains("jpg")){//图片
                FileUtils.copyFile(file,new File("D:\\资料\\CV\\video\\dataset\\image",fileName));
                System.out.println("正在复制图片:"+fileName);
            }
        }else {
            File[] files = file.listFiles();
            for (File temFile : files) {
                String absolutePath = temFile.getAbsolutePath();
                copyFile(absolutePath);
            }
        }
    }

    public static  void reNameFile(){
        String path = "D:\\资料\\video\\capter\\商场";
        File dir = new File(path);
        int i=1;
        for (File file : dir.listFiles()) {
            file.renameTo(new File("D:\\资料\\video\\capter\\商场\\market_"+i+"_"));
            i++;
        }
    }

    public static void removeReFile(String dirNamePath){
        File file = new File(dirNamePath);
        if (file.isDirectory()){
            for (File subFile : file.listFiles()) {
                removeReFile(subFile.getAbsolutePath());
            }
        }
        if(file.isFile()){
            fileNameMap.put(file.length(),file.getAbsolutePath());
        }

    }

    public static void counFile(String path){
        File dir = new File(path);
        int i=0;
        for (File file : dir.listFiles()) {
            i += file.listFiles().length;
        }
        System.out.println(i);
    }

}